<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\Post\ImportBannedNoticeLogPost;
use App\Admin\Extensions\UserForbiddenOp;
use App\Admin\Extensions\UserFreezeOp;
use App\Admin\Extensions\UserOp;
use App\Http\Controllers\Controller;
use App\Model\BannedNoticeLog;
use App\Model\Message;
use App\Model\SuperAdmin;
use App\Model\User;
use App\Model\UserForbidden;
use App\Model\UserFreezeLog;
use App\Model\UserProfile;
use App\Model\VideoLink;
use App\Util\InfoUtil;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Form;
use Encore\Admin\Form\Tools;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;

class ViolationPublicizeController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header('违规名单公示');
            $content->description('');
            $content->body($this->grid());
        });
    }

    public function edit($id)
    {
        $content = new Content();
        $content->header('编辑');
        $content->body($this->form()->edit($id));
        return $content;
    }

    public function create()
    {
        return Admin::content(function (Content $content) {
            $content->header('添加');
            $content->description('');
            $content->body($this->form());
        });
    }

    protected function grid()
    {
        return Admin::grid(BannedNoticeLog::class, function (Grid $grid) {
            $grid->model()->orderBy('id', 'desc', 'adminUser');
            $grid->user_profile_id('用户外部ID');
            $grid->type_str('封禁类型');
            $grid->banned_str('处理结果');

            //禁用导出
            $grid->disableExport();
            $grid->disableActions();

            $grid->tools(function (Grid\Tools $tools) {
                $tools->append(new ImportBannedNoticeLogPost());
            });
        });
    }

    protected function form($mode = '', $id = '')
    {
        return Admin::form(BannedNoticeLog::class, function (Form $form) use ($mode, $id) {
            $form->text('user_profile_id', '用户外部ID');
            $form->text('type_str', '封禁类型');
            $form->text('banned_str', '处理结果');
        });
    }
}
